/**
 * Common
 * @file 公用Hooks
 * @module src/models/common.ts
 * @author yunqilaohe
 */
import { useState, useCallback } from 'react';
import { getPolicyOrgs } from '@/services/homePage/homePage';

export interface PolicyOrganizationsState {
  createTime: string;
  id: number;
  orgName: string;
  orgType: string;
  parentId: null | number;
  updateTime: string;
}

export default () => {
  const [policyOrganizations, setPolicyOrganizations] = useState<PolicyOrganizationsState[]>([]);

  const getPolicyOrganizations = useCallback(async () => {
    const { results = [] } = await getPolicyOrgs();
    setPolicyOrganizations(results);
  }, []);

  return { policyOrganizations, getPolicyOrganizations };
};
